/* ----------------------------------------------------------------------
*
* Copyright (C) 2024 XiaoFei. All rights reserved.
*
* $file:		LingZhi_AD9959.h
* $Date:        19-July-2024
* $Revision: 	V1
* $Project: 	XiaoFei BSP Library
* $Taobao:      https://item.taobao.com/item.htm?abbucket=17&id=561466801051
*
* -------------------------------------------------------------------- */

#ifndef __LingZhi_AD9959_H
#define __LingZhi_AD9959_H

#define AD9959_RCC_PDN(x)				RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,(FunctionalState)x)
#define AD9959_RCC_RST(x)				RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,(FunctionalState)x)
#define AD9959_RCC_SD0(x)	            RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,(FunctionalState)x)
#define AD9959_RCC_SD1(x)	            RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,(FunctionalState)x)
#define AD9959_RCC_SD2(x)	            RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,(FunctionalState)x)
#define AD9959_RCC_SD3(x)	            RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,(FunctionalState)x)
#define AD9959_RCC_SCK(x)               RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,(FunctionalState)x)
#define AD9959_RCC_CS(x)	            RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,(FunctionalState)x)
#define AD9959_RCC_IU(x)                RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,(FunctionalState)x)
#define AD9959_RCC_P0(x)                RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,(FunctionalState)x)
#define AD9959_RCC_P1(x)                RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE,(FunctionalState)x)
#define AD9959_RCC_P2(x)                RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,(FunctionalState)x)
#define AD9959_RCC_P3(x)                RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,(FunctionalState)x)
#define AD9959_GPIO_PDN					GPIOD
#define AD9959_GPIO_RST					GPIOD
#define AD9959_GPIO_SD0	                GPIOD
#define AD9959_GPIO_SD1	                GPIOD
#define AD9959_GPIO_SD2	                GPIOD
#define AD9959_GPIO_SD3	                GPIOD
#define AD9959_GPIO_SCK                 GPIOD
#define AD9959_GPIO_CS         	        GPIOD
#define AD9959_GPIO_IU                  GPIOD
#define AD9959_GPIO_P0                  GPIOD
#define AD9959_GPIO_P1                  GPIOE
#define AD9959_GPIO_P2                  GPIOD
#define AD9959_GPIO_P3                  GPIOD
#define AD9959_PIN_PDN					GPIO_Pin_0
#define AD9959_PIN_RST					GPIO_Pin_1
#define AD9959_PIN_SD0	                GPIO_Pin_5
#define AD9959_PIN_SD1	                GPIO_Pin_4
#define AD9959_PIN_SD2	                GPIO_Pin_3
#define AD9959_PIN_SD3	                GPIO_Pin_2
#define AD9959_PIN_SCK         	        GPIO_Pin_6
#define AD9959_PIN_CS	        	    GPIO_Pin_7
#define AD9959_PIN_IU          	        GPIO_Pin_8
#define AD9959_PIN_P0          	        GPIO_Pin_12
#define AD9959_PIN_P1          	        GPIO_Pin_7
#define AD9959_PIN_P2          	        GPIO_Pin_10
#define AD9959_PIN_P3          	        GPIO_Pin_11
#define AD9959_PDN(x)					GPIO_WriteBit(AD9959_GPIO_PDN,AD9959_PIN_PDN,(BitAction)(x))
#define AD9959_RST(x)					GPIO_WriteBit(AD9959_GPIO_RST,AD9959_PIN_RST,(BitAction)(x))
#define AD9959_SD0(x)	       	 	    GPIO_WriteBit(AD9959_GPIO_SD0,AD9959_PIN_SD0,(BitAction)(x))
#define AD9959_SD1(x)	        	    GPIO_WriteBit(AD9959_GPIO_SD1,AD9959_PIN_SD1,(BitAction)(x))
#define AD9959_SD2(x)	        	    GPIO_WriteBit(AD9959_GPIO_SD2,AD9959_PIN_SD2,(BitAction)(x))
#define AD9959_SD3(x)	        	    GPIO_WriteBit(AD9959_GPIO_SD3,AD9959_PIN_SD3,(BitAction)(x))
#define AD9959_SCK(x)         	        GPIO_WriteBit(AD9959_GPIO_SCK,AD9959_PIN_SCK,(BitAction)(x))
#define AD9959_CS(x)        		    GPIO_WriteBit(AD9959_GPIO_CS,AD9959_PIN_CS,(BitAction)(x))
#define AD9959_IU(x)         		    GPIO_WriteBit(AD9959_GPIO_IU,AD9959_PIN_IU,(BitAction)(x))
#define AD9959_P0(x)         		    GPIO_WriteBit(AD9959_GPIO_P0,AD9959_PIN_P0,(BitAction)(x))
#define AD9959_P1(x)         		    GPIO_WriteBit(AD9959_GPIO_P1,AD9959_PIN_P1,(BitAction)(x))
#define AD9959_P2(x)         		    GPIO_WriteBit(AD9959_GPIO_P2,AD9959_PIN_P2,(BitAction)(x))
#define AD9959_P3(x)         		    GPIO_WriteBit(AD9959_GPIO_P3,AD9959_PIN_P3,(BitAction)(x))

#define	AD9959_SysClk					500000000
#define AD9959_CSR 						0x00   
#define AD9959_FR1 						0x01   
#define AD9959_FR2 						0x02   
#define AD9959_CFR 						0x03   
#define AD9959_CFTW0 					0x04   
#define AD9959_CPOW0 					0x05   
#define AD9959_ACR 						0x06   
#define AD9959_SRR 						0x07   
#define AD9959_RDW 						0x08   
#define AD9959_FDW 						0x09   

#ifndef AD9959_ChanDef_def
#define AD9959_ChanDef_def
typedef enum
{
	AD9959_Chan0=0x10 ,         /*!< The AD9959 Channel 0 */
	AD9959_Chan1=0x20 ,         /*!< The AD9959 Channel 1 */
	AD9959_Chan2=0x40 ,         /*!< The AD9959 Channel 2 */
	AD9959_Chan3=0x80           /*!< The AD9959 Channel 3 */
}AD9959_ChanDef;
#endif

#ifndef AD9959_MoodDef_def
#define AD9959_MoodDef_def
typedef enum
{
	AD9959_MoodFre=0x00 ,       /*!< The AD9959 frequency mood */
	AD9959_MoodPha=0x01 ,       /*!< The AD9959 frequency and phase mood */
	AD9959_MoodAmp=0x02 ,       /*!< The AD9959 frequency and amplitute mood */
}AD9959_MoodDef;
#endif

#ifndef AD9959_DataDef_def
#define AD9959_DataDef_def
typedef struct
{
	AD9959_ChanDef chan;        /*!< The channel be used from AD9959 */
	double freq;                /*!< The frequency of the wave */
	double phase;               /*!< The phase of the wave */
	int amp;                    /*!< The amplitute of the wave */
}AD9959_DataDef;
#endif

/* 
* @function: 	LingZhi_AD9959_Init
*/
void LingZhi_AD9959_Init(void);

/* 
* @function:    LingZhi_AD9959_SetWave
* @parameter:   [in] mood				The AD9959 work mood.
* @parameter:   [in] data				The main data of the wave.
*/
void LingZhi_AD9959_SetWave(AD9959_MoodDef mood, AD9959_DataDef* data);

#endif


